<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>车辆管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>
<style>
    .navbar {
        border-radius: 10px;
        background-color: #343a40;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        padding: 10px 0;
        transition: all 0.3s ease-in-out;
    }

    .navbar:hover {
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    }

    /* 增加一些 padding 和 margin 让内容不那么拥挤 */
    .navbar-brand {
        font-weight: bold;
        font-size: 1.25rem;
        color: #ffffff;
        text-transform: uppercase;
        transition: color 0.3s ease;
    }

    .navbar-brand:hover {
        color: #2980b9;
    }

    /* 菜单项样式 */
    .navbar-nav .nav-item .nav-link {
        color: #ffffff;
        font-weight: 500;
        padding: 12px 8px;
        transition: background-color 0.3s ease, color 0.3s ease;
    }

    .navbar-nav .nav-item .nav-link:hover,
    .navbar-nav .nav-item .nav-link:focus {
        color: #ffffff;
        background-color: #2980b9;
        border-radius: 5px;
    }

    .navbar-nav .nav-item.active .nav-link {
        color: #fff;
        background-color: #2980b9;
        border-radius: 5px;
    }

    /* 用户信息和退出登录 */
    .navbar-nav.ms-auto .nav-link {
        color: #ffffff;
        font-weight: 500;
        padding: 12px 20px;
    }

    .navbar-nav.ms-auto .nav-link:hover {
        background-color: #2ecc71;
        color: #fff;
        border-radius: 5px;
    }

    /* 自适应 */
    @media (max-width: 768px) {
        .navbar-collapse {
            margin-top: 10px;
        }
    }
    :root {
        --primary-color: #3498db;
        --secondary-color: #2ecc71;
        --dark-color: #2c3e50;
        --light-color: #ecf0f1;
        --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }

    body {
        background-color: #f8f9fa;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    .container {
        max-width: 1270px;

    }

    .card {
        border: none;
        border-radius: 10px;
        box-shadow: var(--shadow);
        margin-bottom: 25px;
        overflow: hidden;
    }

    .card-header {
        background-color: var(--dark-color);
        color: white;
        font-weight: 600;
        padding: 15px 20px;
        border-bottom: none;
    }

    .table-responsive {
        border-radius: 0 0 10px 10px;
        overflow: hidden;
    }

    .table {
        margin-bottom: 0;
    }

    .table thead th {
        background-color: var(--dark-color);
        color: white;
        position: sticky;
        top: 0;
    }

    .table-striped tbody tr:nth-of-type(odd) {
        background-color: rgba(0, 0, 0, 0.02);
    }

    .table-hover tbody tr:hover {
        background-color: rgba(0, 0, 0, 0.05);
    }

    .btn-primary {
        background-color: var(--primary-color);
        border-color: var(--primary-color);
    }

    .btn-outline-primary {
        color: var(--primary-color);
        border-color: var(--primary-color);
    }

    .btn-outline-primary:hover {
        background-color: var(--primary-color);
        color: white;
    }

    .btn-outline-danger:hover {
        background-color: #e74c3c;
        color: white;
    }

    .alert {
        border-radius: 8px;
        border: none;
    }

    .input-group {
        box-shadow: var(--shadow);
    }

    .form-control:focus {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 0.25rem rgba(52, 152, 219, 0.25);
    }

    .badge {
        font-weight: 500;
        padding: 0.5em 0.75em;
    }

    .badge.bg-warning {
        background-color: #f39c12 !important;
        color: white;
    }

    .badge.bg-success {
        background-color: #2ecc71 !important;
    }

    .pagination .page-item.active .page-link {
        background-color: var(--primary-color);
        border-color: var(--primary-color);
    }

    .pagination .page-link {
        color: var(--dark-color);
    }

    @media (max-width: 768px) {
        .container {
            padding: 15px;
        }

        .card-header {
            flex-direction: column;
            align-items: flex-start;
        }

        .card-header h5 {
            margin-bottom: 10px;
        }

        .btn-group {
            flex-wrap: wrap;
        }

        .table-responsive {
            overflow-x: auto;
        }
    }
</style>
<body>
<div th:insert="~{common/common::topbar}"></div>

<div class="container mt-4">
    <div class="row">
        <div class="col-md-12">
            <div th:if="${errorMessage}" class="alert alert-danger" th:text="${errorMessage}"></div>
            <div class="alert alert-success" th:if="${success}" th:text="${success}"></div>
            <div class="alert alert-danger" th:if="${error}" th:text="${error}"></div>

            <div class="card">

                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">车辆管理</h5>
                    <a th:href="@{/vehicle/toaddvehicle}" class="btn btn-primary btn-sm">
                        <i class="bi bi-plus-circle"></i> 新增车辆
                    </a>
                </div>
<!--                <div class="card-body">-->
<!--                    <form method="get" th:action="@{/vehicle/search}">-->
<!--                        <div class="row">-->
<!--                            <div class="col-md-6 mb-2">-->
<!--                                <input type="text" class="form-control" name="license_plate" placeholder="车牌号" >-->
<!--                            </div>-->
<!--                            <div class="col-12">-->
<!--                                <button class="btn btn-primary" type="submit">-->
<!--                                    <i class="bi bi-search"></i> 搜索-->
<!--                                </button>-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </form>-->
<!--                </div>-->
                <div class="mb-4">
                    <form method="get" th:action="@{/vehicle/search}">
                        <div class="input-group">
                            <input type="text" class="form-control" name="license_plate" placeholder="车牌号" >
                            <button class="btn btn-outline-secondary" type="submit">
                                <i class="bi bi-search"></i> 搜索
                            </button>
                        </div>
                    </form>
                </div>

                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                            <tr>
                                <th>车辆ID</th>
                                <th>客户姓名</th>
                                <th>车牌号</th>
                                <th>车辆品牌</th>
                                <th>购买日期</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="vehicle : ${vehicleList}">
                                <td th:text="${vehicle.vehicle_id}"></td>
                                <td th:text="${vehicle.customer_name}"></td>
                                <td th:text="${vehicle.license_plate}"></td>
                                <td th:text="${vehicle.brand}"></td>
                                <td th:text="${vehicle.purchase_date}"></td>
                                <td>
                                    <div class="btn-group btn-group-sm">
                                        <a th:href="@{/vehicle/edit/}+${vehicle.vehicle_id}"
                                           class="btn btn-outline-primary">
                                            <i class="bi bi-pencil"></i> 编辑
                                        </a>
                                        <a th:href="@{/vehicle/delvehicle/}+${vehicle.vehicle_id}"
                                           class="btn btn-outline-danger"
                                           onclick="return confirm('确定要删除此车辆吗？')">
                                            <i class="bi bi-trash"></i> 删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            <tr th:if="${#lists.isEmpty(vehicleList)}">
                                <td colspan="6" class="text-center">没有找到车辆记录</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                <!-- 分页导航 -->
                <nav th:if="${vehicleList != null and not #lists.isEmpty(vehicleList)}" aria-label="分页导航">
                    <ul class="pagination justify-content-center mt-3">
                        <li class="page-item" th:classappend="${currentPage == 1} ? 'disabled' : ''">
                            <a class="page-link" th:href="@{/vehicle/lists(page=1, key=${key})}" aria-label="首页">
                                <span aria-hidden="true">&laquo;&laquo;</span>
                            </a>
                        </li>
                        <li class="page-item" th:classappend="${currentPage == 1} ? 'disabled' : ''">
                            <a class="page-link" th:href="@{/vehicle/lists(page=${currentPage - 1}, key=${key})}" aria-label="上一页">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <li class="page-item" th:each="i : ${#numbers.sequence(1, totalPages)}"
                            th:classappend="${currentPage == i} ? 'active' : ''">
                            <a class="page-link" th:href="@{/vehicle/lists(page=${i}, key=${key})}" th:text="${i}"></a>
                        </li>
                        <li class="page-item" th:classappend="${currentPage == totalPages} ? 'disabled' : ''">
                            <a class="page-link" th:href="@{/vehicle/lists(page=${currentPage + 1}, key=${key})}" aria-label="下一页">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                        <li class="page-item" th:classappend="${currentPage == totalPages} ? 'disabled' : ''">
                            <a class="page-link" th:href="@{/vehicle/lists(page=${totalPages}, key=${key})}" aria-label="末页">
                                <span aria-hidden="true">&raquo;&raquo;</span>
                            </a>
                        </li>
                        <li class="page-item">
                            <div class="input-group" style="width: 150px; margin-left: 10px;">
                                <input type="number" class="form-control" id="pageInput"
                                       min="1" th:attr="max=${totalPages}"
                                       th:value="${currentPage}"
                                       placeholder="页码">
                                <button class="btn btn-outline-secondary" type="button" id="goToPageBtn">
                                    跳转
                                </button>
                            </div>
                        </li>
                    </ul>
                </nav>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>